#!/bin/bash
# 文件重复检查脚本
# 用于检查 cbp2make 和基础库之间的文件重复情况

cd /d/vc/UEStudio/src

echo "=== 系统检查文件重复情况 ==="
echo ""

echo "1. tinyxml 库文件对比:"
echo "基础库文件:"
find base/tinyxml -name "*.cpp" -o -name "*.h" | sort
echo "cbp2make 本地文件:"
find tools/cbp2make/lib/tinyxml -name "*.cpp" -o -name "*.h" 2>/dev/null | sort
echo ""

echo "2. STL 工具库文件对比:"
echo "基础库文件:"
find base -name "stl*.cpp" -o -name "stl*.h" | sort
echo "cbp2make 本地文件:"
find tools/cbp2make/lib -name "stl*.cpp" -o -name "stl*.h" 2>/dev/null | sort
echo ""

echo "3. 字符串哈希库对比:"
echo "基础库文件:"
find base -name "stringhash*" | sort
echo "cbp2make 本地文件:"
find tools/cbp2make/lib -name "stringhash*" 2>/dev/null | sort
echo ""

echo "4. 文件内容对比（抽样）:"

# 对比 tinyxml.cpp
echo "对比 tinyxml.cpp:"
if [ -f "base/tinyxml/tinyxml.cpp" ] && [ -f "tools/cbp2make/lib/tinyxml/tinyxml.cpp" ]; then
    diff -q base/tinyxml/tinyxml.cpp tools/cbp2make/lib/tinyxml/tinyxml.cpp
    if [ $? -eq 0 ]; then
        echo "✅ 文件内容完全相同"
    else
        echo "❌ 文件内容不同"
        wc -l base/tinyxml/tinyxml.cpp tools/cbp2make/lib/tinyxml/tinyxml.cpp
    fi
fi

echo ""

# 对比 stlstrings.cpp
echo "对比 stlstrings.cpp:"
if [ -f "base/tinyxml/stlstrings.cpp" ] && [ -f "tools/cbp2make/lib/stlstrings.cpp" ]; then
    diff -q base/tinyxml/stlstrings.cpp tools/cbp2make/lib/stlstrings.cpp
    if [ $? -eq 0 ]; then
        echo "✅ 文件内容完全相同"
    else
        echo "❌ 文件内容不同"
        wc -l base/tinyxml/stlstrings.cpp tools/cbp2make/lib/stlstrings.cpp
    fi
elif [ -f "tools/cbp2make/lib/stlstrings.cpp" ]; then
    echo "只在 cbp2make 中找到 stlstrings.cpp"
fi

echo ""

echo "5. 详细文件对比列表:"
find tools/cbp2make -name "*.cpp" -o -name "*.h" | while read file; do
    filename=$(basename "$file")
    base_file=$(find base -name "$filename" -type f | head -1)
    
    if [ -n "$base_file" ] && [ -f "$base_file" ] && [ -f "$file" ]; then
        if diff -q "$base_file" "$file" >/dev/null 2>&1; then
            echo "✅ 完全相同: $filename"
        else
            echo "⚠️  文件不同: $filename (基础库:$(wc -l < "$base_file")行, cbp2make:$(wc -l < "$file")行)"
        fi
    elif [ -f "$file" ]; then
        echo "🔸 cbp2make 独有: $filename"
    fi
done
